package cn.lg.soar.message.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;

import java.util.Collection;

/**
 * websocket服务
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class WebSocketService  {

    @Autowired
    private WebSocketManager manager;

    /**
     * 广播消息
     * @param message
     */
    @Async
    public void sendMsgAllAsync(String topic, String message) {
        manager.sendMsgAll(topic, message);
    }

    /**
     * 发送消息
     */
    @Async
    public void sendMsgByUserAsync(String topic, String message, Collection<Long> userIds) {
        manager.sendMsgByUser(topic, message, userIds);
    }

    /**
     * 发送消息
     */
    @Async
    public void sendMsgByUserAsync(String topic, String message, Long...userIds) {
        manager.sendMsgByUser(topic, message, userIds);
    }

    /**
     * 同步发送消息
     */
    public Collection<Long> sendMsgByUser(String topic, String message, Collection<Long> userIds) {
        return manager.sendMsgByUser(topic, message, userIds);
    }

    /**
     * 同步发送消息
     */
    public Collection<Long> sendMsgByUser(String topic, String message, Long...userIds) {
        return manager.sendMsgByUser(topic, message, userIds);
    }

    /**
     * 同步发送消息
     */
    public boolean sendMsgByClient(String topic, String message, String clientId) {
        return manager.sendMsgByClient(topic, message, clientId);
    }

}
